package fr.mairie.parc.page.materiel;

import java.util.List;

import javax.annotation.Resource;

import org.apache.click.control.Form;
import org.apache.click.control.PageLink;
import org.apache.click.dataprovider.DataProvider;
import org.apache.click.util.Bindable;
import org.springframework.context.ApplicationContext;

import fr.mairie.parc.context.AppContext;
import fr.mairie.parc.control.materiel.MaterielFields;
import fr.mairie.parc.control.materiel.MaterielTable;
import fr.mairie.parc.domain.Materiel;
import fr.mairie.parc.page.BorderPage;
import fr.mairie.parc.service.MaterielManager;

public class MaterielPage extends BorderPage {

	/**
	 *
	 */
	private static final long serialVersionUID = 1L;

	@Resource protected MaterielManager materielManager;
	@Bindable protected MaterielTable resultTable = new MaterielTable("resultTable", this, ViewMaterielPage.class);
	@Bindable protected Form bottomButtons = new Form("bottomButtons");

	protected MaterielFields fields = new MaterielFields();

	public MaterielPage() {

		resultTable.setDataProvider(new DataProvider<Materiel>() {
			private static final long serialVersionUID = 1L;
			public Iterable<Materiel> getData() {
				List<Materiel> res = materielManager.selectAll();
		    	return res;
		    }
		});

		PageLink validationRowLink = new PageLink("Validate", EditMaterielPage.class);
		validationRowLink.setImageSrc("/assets/images/16x16/application_form_edit.png");
		validationRowLink.setTitle("Edit Validation");
		//validationRowLink.setParameter("referrer", "list-user-dif-request.htm");

		resultTable.addActionColumnLink(validationRowLink);
	}

	@Override
	public void onInit() {
		super.onInit();
		ApplicationContext ctx = AppContext.getApplicationContext();
    	materielManager = (MaterielManager) ctx.getBean("materielManager");
	}


}
